package com.zz.services.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zz.dao.UserDao;
import com.zz.domain.User;
import com.zz.services.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserDao userDao;
    @Override
    public User login(User user) {
        Map<String,Object> param = new HashMap<>();
        param.put("email",user.getEmail());
        param.put("password",user.getPassword());
        return userDao.findUserByCondition(param);
    }

    @Override
    public int register(User user) {
        user.setVipFlag("0");
        user.setCreateTime(new Date());
        return  userDao.addUser(user);

    }

    @Override
    public User existEmail(String email) {
        Map<String,Object> param = new HashMap<>();
        param.put("email",email);
        return  userDao.findUserByCondition(param);
    }

    @Override
    public PageInfo<User> getUserList() {
        PageHelper.startPage(1,16);
        List<User> userList = userDao.findUserAll();
        PageInfo<User> userPageInfo = new PageInfo<>(userList,4);
        return userPageInfo;
    }
}
